Python for Teenagers by James R. Payne
Author:James R. Payne
Language: eng
Format: epub
ISBN: 9781484245507
Publisher: Apress
class Mutate(Superhero):
def __init__(self):
Superhero.__init__(self)
print("You created a Mutate!")
self.speed = self.speed + 10
# Creating a subclass of Superhero named Robot
# Robot heroes will get a + 10 bonus to their braun score.
class Robot(Superhero):
def __init__(self):
Superhero.__init__(self)
print("You created a robot!")
self.braun = self.braun + 10
Here, we have created two new classes, which are both actually subclasses of our Superhero class. The way we achieve this is by putting the name of the parent class in the parentheses of the newly created class. For example: class Mutate(Superhero) tells the Python interpreter to create a class that is a child or subclass of Superhero and inherit its methods and parameters.
We then initialize our new subclass using def __init__(self) and re-initialize our Superhero class using Superhero.__init__(self), since we will be creating new objects based off of, technically, both the class and subclass.
Finally, we want to give our heroes a bonus based off of which type of hero they are. The mutate character will receive a bonus to speed, as shown in this line of code:self.speed = self.speed + 10
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hands-On Python Deep Learning for the Web by Anubhav Singh(2034)
Mastering OpenCV 4 with Python by Fernández Villán Alberto;(1947)
Python Feature Engineering Cookbook by Soledad Galli(1941)
Applied Deep Learning with Keras by Matthew Moocarme Mahla Abdolahnejad and Ritesh Bhagwat(1780)
Building Serverless Python Web Services with Zappa by Abdulwahid Abdulhaque Barguzar(1743)
Python for Finance: Analyze Big Financial Data by Yves Hilpisch(1737)
Python for Finance Cookbook by Eryk Lewinson(1719)
Mastering Python Data Visualization by Kirthi Raman(1705)
PYTHON PROGRAMMING ADVANCED: The Guide for Data Analysis and Data Science. Discover Machine Learning With the Optimum Recipes for Mastering Python and ... (Crash Course Tips and Tricks Book 3) by ERIC MATTHEWS & LEWIS TAYLOR(1656)
Django 3 By Example by Antonio Melé(1614)
Supervised Machine Learning with Python by Taylor Smith(1597)
Interactive Data Visualization with Python by Anshu Kumar & Shubhangi Hora & Sharath Chandra Guntuku & Abha Belorkar(1449)
Hands-On GPU Programming with Python and CUDA by Dr. Brian Tuomanen(1368)
Hands-On Image Processing with Python by Sandipan Dey(1338)
Scientific Computing with Python 3 by Claus Fuhrer & Jan Erik Solem & Olivier Verdier(1325)
Flask Framework Cookbook by Shalabh Aggarwal(1302)
Python Deep Learning. by Ivan Vasilev(1278)
Training Systems using Python Statistical Modeling by Curtis Miller(1269)
Django 3 Web Development Cookbook - Fourth Edition by Aidas Bendoraitis(1260)
